﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Loki.Core.Model.Test
{
	public class DummyLoader
	{
		public Dictionary<Guid, int> LoadedPKAsks = new Dictionary<Guid, int>();
		public Dictionary<int, int> LoadedKey1Asks = new Dictionary<int, int>();
		public int LoadAll = 0;
		public Dictionary<Guid, int> PreUpdateAsk = new Dictionary<Guid, int>();
		public Dictionary<Guid, int> PostUpdateAsk = new Dictionary<Guid, int>();

		public DummyEntity[] Store = new DummyEntity[] 
		{
			new DummyEntity(){ID = Guid.NewGuid(), Key1 = 1, Key2 = "A", Value = "KKK"},
			new DummyEntity(){ID = Guid.NewGuid(), Key1	= 1, Key2 = "C", Value = "KKK"},
			new DummyEntity(){ID = Guid.NewGuid(), Key1 = 5, Key2 = "C", Value = "KKK"}
		};

		public DummyEntity NotStored = new DummyEntity() { ID = Guid.NewGuid(), Key1 = 5, Key2 = "C", Value = "KKK" };

		public static DummyEntity Empty(Guid P_ID)
		{
			return new DummyEntity() { ID = P_ID, Key1 = 0, Value = "00", Key2 = "0" };
		}

		public IEnumerable<DummyEntity> GetAllByKey1(int P_Key1)
		{
			if (!LoadedKey1Asks.ContainsKey(P_Key1))
				LoadedKey1Asks[P_Key1] = 0;
			LoadedKey1Asks[P_Key1]++;
			return Store.Where(x => x.Key1 == P_Key1);
		}

		public DummyEntity Get(Guid P_PK)
		{
			if (!LoadedPKAsks.ContainsKey(P_PK))
				LoadedPKAsks[P_PK] = 0;
			LoadedPKAsks[P_PK]++;
			if (P_PK == Guid.Empty)
				return null;
			else 
			{
				DummyEntity L_Entity = new DummyEntity() { ID = P_PK, Key1 = 0, Key2 = null, Value = "KKK" };
				return L_Entity;
			}
		}

		public IEnumerable<DummyEntity> GetAll()
		{
			LoadAll++;
			return Store;
		}

		public void PostUpdate(Guid P_Key)
		{
			if (PostUpdateAsk.ContainsKey(P_Key))
				PostUpdateAsk[P_Key] = 0;
			PostUpdateAsk[P_Key]++;
		}

		public void PreUpdate(Guid P_Key)
		{
			if (PreUpdateAsk.ContainsKey(P_Key))
				PreUpdateAsk[P_Key] = 0;
			PreUpdateAsk[P_Key]++;
		}
	}
}
